#!/usr/bin/python
# coding=utf-8
def onKeyDown(event):
	msgbox("received key input event")
	if console.getMode() == "chat":
		console.addWidget("chat_row", text=event.key)
	elif console.getMode() == "game":
		if	event.isShift == True:
			console.addWidget("unit", type=event.key, x=1, y=2, color="ally") #type, char, x, y, owner/color
		else:
			if event.key == "a":
				game.sendCommand("attack", unitId=game.getSelectedUnitId(), targetType="unit", targetId=42)

def onActionUpdate(event):
	msgbox("received update action event")
	if console.getMode() == "game":
		if event.targetType=="unit":
			widget=console.getWidget(type="unit", id=event.unitId)
			widget.moveTo(event.targetX, event.targetY)
		elif event.targetType=="building":
			widget=console.getWidget(type="building", id=event.buildingId)
			widget.moveTo(event.targetX, event.targetY)
	else:
		pass

print "Initializing the game... ",
import pe
print "ok"
console=pe.screenConsole()
#sound=pe.screenPCSpeaker()
#logfile=pe.screenFile("log.txt")

pe.setCallback(onKeyDown, "INPUT_KEY", console)
pe.setCallback(onActionUpdate, "ACTION_UPDATE")
if console.msgbox(text="Hra spuštěna"):
	console.msgbox(text="Jou, stiskls enter!")
print console.msgbox(text="Program se nyní ukončí.")

game=pe.game(serverIp="127.0.0.1")
